<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		$this->load->model('check');
	}
	function index()
	{
		$this->load->view('admin/index');
	}
	function password()
	{
		$temp['info']="";
		$this->load->view('admin/orther/pass',$temp);
	}
	function changpass()
	{
		$where['username']=$this->session->userdata('manager');
		$oldpass=$this->input->post('oldpass');
		$newpass=$this->input->post('newpass');
		$qrpass=$this->input->post('qrpass');
		if($qrpass != $newpass)
		{
			$temp['info']="新密码必须和确认密码一致";
			$this->load->view('admin/orther/pass',$temp);
		}
		else
		{
			$table="admin";
			$where['userpass']=sha1($oldpass);
			$query=$this->db->get_where($table,$where);
			$count=$query->num_rows();
			if($count>0)
			{
				$where_name['username']=$this->session->userdata('manager');
				$arr['userpass']=sha1($newpass);
				$res=$this->db->update($table,$arr,$where_name);
				if($res)
				{
					$this->message->showmessage('修改成功','admin_login/main/password');exit();
				}
				else
				{
					$this->message->showmessage('系统繁忙，修改失败','admin_login/main/password');exit();
				}
			}
			else
			{
				$temp['info']="旧密码输入错误";
				$this->load->view('admin/orther/pass',$temp);
			}
		}
	}
	function sysconfig()
	{
		$table="sysconfig";
		$where['id']=1;
		$query=$this->db->get_where($table,$where);
		$count=$query->num_rows();
		if($count>0)
		{
			$res=$query->result_array();
			$temp['res']=$res;
			$temp['check']=1;
		}
		else
		{
			$temp['title']="";
			$temp['keyword']="";
			$temp['description']="";
			$temp['sitestatic']="";
			$temp['content']="";
			$temp['check']=0;
		}
		//print_r($temp);
		$this->load->view('admin/orther/sysconfig',$temp);
	}
	function change_sysconfig()
	{
		$table="sysconfig";
		$arr['title']=$this->input->post('title');
		$arr['keyword']=$this->input->post('keyword');
		$arr['description']=$this->input->post('description');
		$arr['content']=$this->input->post('content');
		$arr['sitestatic']=$this->input->post('sitestatic');
		$arr['footer']=$this->input->post('footer');
		$check=$this->input->post('check');
		if($check==1)
		{
			$where['id']=1;
			$res=$this->db->update($table,$arr,$where);
		}
		else
		{
			$arr['id']=1;
			$res=$this->db->insert($table,$arr);
		}
		if($res)
		{
			$this->message->showmessage('修改成功','admin_login/main/sysconfig');exit();
		}
		else
		{
			$this->message->showmessage('系统繁忙或填写错误，修改失败，请稍后再试','admin_login/main/sysconfig');exit();
		}
	}
	function lanmu()
	{
		$table="lanmu";
		$this->db->order_by("weizhi","desc"); 
		$query=$this->db->get($table);
		
		$temp['res']=$query->result();
		$this->load->view('admin/orther/lanmu',$temp);
	}
	function add_lanmu()
	{
		$table="lanmu";
		$arr['name']=$this->input->post('name');
		$arr['url']=$this->input->post('url');
		$arr['weizhi']=$this->input->post('weizhi');
		$res=$this->db->insert($table,$arr);
		if($res)
		{
			$this->message->showmessage('添加成功','admin_login/main/lanmu');exit();
		}
		else
		{
			$this->message->showmessage('添加失败，系统繁忙或着填写错误','admin_login/main/lanmu');exit();
		}
	}
	function change_lanmu()
	{
		$table="lanmu";
		$where['id']=$this->input->post('id');
		$arr['name']=$this->input->post('name');
		$arr['url']=$this->input->post('url');
		$arr['weizhi']=$this->input->post('weizhi');
		$res=$this->db->update($table,$arr,$where);
		if($res)
		{
			$this->message->showmessage('修改成功','admin_login/main/lanmu');exit();
		}
		else
		{
			$this->message->showmessage('修改失败，系统繁忙或着填写错误','admin_login/main/lanmu');exit();
		}
	}
	function del_lanmu($id)
	{
		$table="lanmu";
		$where['id']=$id;
		$res=$this->db->delete($table,$where);
		if($res)
		{
			$this->message->showmessage('删除成功','admin_login/main/lanmu');exit();
		}
		else
		{
			$this->message->showmessage('删除失败，系统繁忙或着填写错误','admin_login/main/lanmu');exit();
		}
	}
	function clear()
	{
		$this->load->driver('cache');
		$file = $this->cache->file->clean();
		echo 'ko';
	}
}